﻿using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000A2E RID: 2606
	internal class ChatMemberList : DlgBase<ChatMemberList, ChatMemberBehaviour>
	{
		// Token: 0x17002ED0 RID: 11984
		// (get) Token: 0x06009EFA RID: 40698 RVA: 0x001A4688 File Offset: 0x001A2888
		public override string fileName
		{
			get
			{
				return "GameSystem/ChatMemberList";
			}
		}

		// Token: 0x17002ED1 RID: 11985
		// (get) Token: 0x06009EFB RID: 40699 RVA: 0x001A46A0 File Offset: 0x001A28A0
		public override bool autoload
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17002ED2 RID: 11986
		// (get) Token: 0x06009EFC RID: 40700 RVA: 0x001A46B4 File Offset: 0x001A28B4
		public override bool isHideChat
		{
			get
			{
				return false;
			}
		}

		// Token: 0x06009EFD RID: 40701 RVA: 0x001A46C7 File Offset: 0x001A28C7
		protected override void Init()
		{
			base.Init();
		}

		// Token: 0x06009EFE RID: 40702 RVA: 0x001A46D1 File Offset: 0x001A28D1
		public override void RegisterEvent()
		{
			base.uiBehaviour.m_wrap.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this.WrapContentItemUpdated));
			base.uiBehaviour.m_sprClose.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnCloseClick));
		}

		// Token: 0x06009EFF RID: 40703 RVA: 0x001A4710 File Offset: 0x001A2910
		protected override void OnShow()
		{
			base.OnShow();
			base.uiBehaviour.m_scroll.ResetPosition();
			GroupChatDocument specificDocument = XDocuments.GetSpecificDocument<GroupChatDocument>(GroupChatDocument.uuID);
			specificDocument.ReqGetGroupInfo(DlgBase<XChatView, XChatBehaviour>.singleton.ChatGroupId);
		}

		// Token: 0x06009F00 RID: 40704 RVA: 0x001A4754 File Offset: 0x001A2954
		public void Refresh()
		{
			GroupChatDocument specificDocument = XDocuments.GetSpecificDocument<GroupChatDocument>(GroupChatDocument.uuID);
			bool flag = specificDocument.players != null;
			if (flag)
			{
				CGroupPlayerInfo[] array = new CGroupPlayerInfo[specificDocument.players.Count];
				specificDocument.players.CopyTo(array);
				this.SelectByState(array);
				base.uiBehaviour.m_wrap.SetContentCount(this.players.Count, false);
			}
		}

		// Token: 0x06009F01 RID: 40705 RVA: 0x001A47C0 File Offset: 0x001A29C0
		private void SelectByState(CGroupPlayerInfo[] pp)
		{
			bool flag = this.players == null;
			if (flag)
			{
				this.players = new List<CGroupPlayerInfo>();
			}
			else
			{
				this.players.Clear();
			}
			int i = 0;
			int num = pp.Length;
			while (i < num)
			{
				bool flag2 = pp[i].degree < 0;
				if (flag2)
				{
					bool flag3 = pp[i].roleid != XSingleton<XAttributeMgr>.singleton.XPlayerData.RoleID;
					if (flag3)
					{
						this.players.Add(pp[i]);
					}
				}
				i++;
			}
		}

		// Token: 0x06009F02 RID: 40706 RVA: 0x001A484E File Offset: 0x001A2A4E
		private void OnCloseClick(IXUISprite spr)
		{
			this.SetVisible(false, true);
		}

		// Token: 0x06009F03 RID: 40707 RVA: 0x001A485C File Offset: 0x001A2A5C
		private void WrapContentItemUpdated(Transform t, int index)
		{
			bool flag = this.players == null || this.players[index] == null;
			if (!flag)
			{
				IXUISprite ixuisprite = t.Find("head").GetComponent("XUISprite") as IXUISprite;
				IXUILabel ixuilabel = t.Find("level").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel2 = t.Find("UID").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel3 = t.Find("PPT").GetComponent("XUILabel") as IXUILabel;
				IXUILabelSymbol ixuilabelSymbol = t.Find("name").GetComponent("XUILabelSymbol") as IXUILabelSymbol;
				IXUISprite ixuisprite2 = t.Find("Btn_chat").GetComponent("XUISprite") as IXUISprite;
				IXUISprite ixuisprite3 = t.Find("add").GetComponent("XUISprite") as IXUISprite;
				IXUILabel ixuilabel4 = t.Find("guild").GetComponent("XUILabel") as IXUILabel;
				IXUISprite ixuisprite4 = t.Find("ProfIcon").GetComponent("XUISprite") as IXUISprite;
				int profession = (int)this.players[index].profession;
				ixuisprite4.spriteName = XSingleton<XProfessionSkillMgr>.singleton.GetProfIcon(profession);
				ixuisprite.spriteName = XSingleton<XProfessionSkillMgr>.singleton.GetProfHeadIcon2(profession);
				ixuisprite2.ID = this.players[index].roleid;
				ixuisprite3.ID = this.players[index].roleid;
				string text = this.players[index].guild;
				bool flag2 = string.IsNullOrEmpty(text);
				if (flag2)
				{
					text = XStringDefineProxy.GetString("NONE");
				}
				ixuilabel4.SetText(text);
				ixuisprite2.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnChatClick));
				ixuisprite3.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnFriendClick));
				bool flag3 = DlgBase<XFriendsView, XFriendsBehaviour>.singleton.IsMyFriend(this.players[index].roleid);
				ixuisprite3.SetVisible(!flag3);
				ixuilabel.SetText(this.players[index].level.ToString());
				ixuilabel3.SetText(this.players[index].ppt.ToString());
				ixuilabelSymbol.InputText = this.players[index].rolename;
				ixuilabel2.SetText(this.players[index].uid.ToString());
			}
		}

		// Token: 0x06009F04 RID: 40708 RVA: 0x001A4AEC File Offset: 0x001A2CEC
		private void OnChatClick(IXUISprite spr)
		{
			this.SetVisible(false, true);
			bool flag = !XSingleton<XGameSysMgr>.singleton.IsSystemOpened(XSysDefine.XSys_Friends);
			if (flag)
			{
				int sysid = XFastEnumIntEqualityComparer<XSysDefine>.ToInt(XSysDefine.XSys_Friends);
				int sysOpenLevel = XSingleton<XGameSysMgr>.singleton.GetSysOpenLevel(sysid);
				XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("EXPEDITION_REQUIRED_LEVEL", new object[]
				{
					sysOpenLevel
				}) + XSingleton<XGameSysMgr>.singleton.GetSysName(sysid), "fece00");
			}
			else
			{
				CGroupPlayerInfo player = this.GetPlayer(spr.ID);
				DlgBase<XOtherPlayerInfoView, XOtherPlayerInfoBehaviour>.singleton.SetPlayerInfo(spr.ID, player.rolename, player.setid, player.ppt, player.profession);
				DlgBase<XOtherPlayerInfoView, XOtherPlayerInfoBehaviour>.singleton.PrivateChat(null);
			}
		}

		// Token: 0x06009F05 RID: 40709 RVA: 0x001A4BA8 File Offset: 0x001A2DA8
		private void OnFriendClick(IXUISprite spr)
		{
			ulong id = spr.ID;
			DlgBase<XFriendsView, XFriendsBehaviour>.singleton.AddFriendById(id);
		}

		// Token: 0x06009F06 RID: 40710 RVA: 0x001A4BCC File Offset: 0x001A2DCC
		private CGroupPlayerInfo GetPlayer(ulong roleid)
		{
			bool flag = this.players != null;
			if (flag)
			{
				foreach (CGroupPlayerInfo cgroupPlayerInfo in this.players)
				{
					if(cgroupPlayerInfo.roleid == roleid)
                    {
						return cgroupPlayerInfo;

					}
// 					bool flag2 = cgroupPlayerInfo.roleid == roleid;
// 					if (flag2)
// 					{
// 						List<CGroupPlayerInfo>.Enumerator enumerator;
// 						return enumerator.Current;
// 					}
				}
			}
			return null;
		}

		// Token: 0x040038AD RID: 14509
		private List<CGroupPlayerInfo> players;
	}
}
